Clock.tsx ➔ Clock   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8
c 0
b 0
f 0
cc 1
1
import React, {useState, useEffect} from "react";
2
3
function Clock(): JSX.Element {
4
  const [date, setDate] = useState<Date>(new Date());
5
6
  useEffect(() => {
7
    const interval = setInterval(() => {
8
      setDate(new Date());
9
    }, 1000);
10
11
    return () => {
12
      clearInterval(interval);
13
    };
14
  });
15
16
  return <span>{date.toLocaleTimeString()}</span>;
17
}
18
19
export default Clock;
20